"""
進入爱逛卖家版
"""
import time

import yaml
from uiautomator2 import xpath

from page_object.add_market_page import AddGoodsPage
from page_object.guang_page import GuangPage
from resource.path_info import *

"""
商品来源配置
"""
class SourceConfigPage(GuangPage):


    def check_bund_records(self, d):
        print("check_bund_records")
        d.xpath(binding_config_but_xpath).click()
        d.xpath(check_first_binding_xpath).wait(timeout=3.0)
        if d.xpath(check_first_binding_xpath).exists:
            print("check bund records successfully")
        else:
            raise Exception("check bund records empty")
        d.press("back")
        d.press("back")
        return self

    def unbind_shop(self,d):
        if d.xpath(unbind_but_xpath).exists:
            #先取消，取消绑定场馆
            d.xpath(unbind_but_xpath).click()
            d(text="取消").click()
            assert True == d.xpath(unbind_but_xpath).exists
            #确认取消绑定
            d.xpath(unbind_but_xpath).click()
            d(text="确定").click()
            assert True != d.xpath(unbind_but_xpath).exists
            d.press("back")
            if not d.xpath(toSourceConfig_xpath).exists:
                d.press("back")
        return self

    def bind_single_shop(self,d):
        if d.xpath(to_bind_but_xpath).exists:
            #先取消，取消绑定
            d.xpath(to_bind_but_xpath).click()
            d.xpath(select_single_box_xpath).wait(timeout=3.0)
            if d.xpath(select_single_box_xpath).exists:
                d.xpath(select_single_box_xpath).click()
            else:
                raise Exception("No shop can bind")
            d.xpath(confirm_but_xpath).click()
            d.xpath(mall_title_xpath).wait(timeout=3.0)
            d.press("back")
        return self

    def bind_multiple_shop(self,d):
        if d.xpath(to_bind_but_xpath).exists:
            d.xpath(to_bind_but_xpath).click()
        d.xpath(to_multi_tab_xpath).click()
        d.xpath(ivExpand_icon_xpath).wait(timeout=3.0)
        if d.xpath(ivExpand_icon_xpath).exists:
            d.xpath(ivExpand_icon_xpath).click()
        d.xpath(select_mul_box_xpath).wait(timeout=3.0)
        if d.xpath(select_mul_box_xpath).exists:
            d.xpath(select_mul_box_xpath).click()
        else:
            raise Exception("No shop can bind")
        d.xpath(confirm_but_xpath).click()
        d.xpath(mall_title_xpath).wait(timeout=3.0)
        d.press("back")
        return self


